import { reqGetTrade, reqAddress } from "@/api/index.js";
const state = {
  getTrade: {},
  getAddress: [],
};
const mutations = {
  GETTRADE(state, getTrade) {
    state.getTrade = getTrade;
  },
  GETADDRESS(state, getAddress) {
    state.getAddress = getAddress;
  },
};
const actions = {
  async getTrade({ commit }) {
    let result = await reqGetTrade();

    if (result.code == 200) {
      commit("GETTRADE", result.data);

      return "ok";
    } else {
      return Promise.reject(new Error("faile"));
    }
  },

  async getAddress({ commit }) {
    let result = await reqAddress();
    if (result.code == 200) {
      commit("GETADDRESS", result.data);
      return "ok";
    } else {
      return Promise.reject(new Error("faile"));
    }
  },
};
const getters = {
  getAddress(state) {
    return state.getAddress || [];
  },
  getTrade(state) {
    return state.getTrade || [];
  },
};
export default {
  state,
  mutations,
  actions,
  getters,
};
